// This is a part of the WceUi library.
// Copyright (C) WceUi Team
// All rights reserved.
//
// Coded by Hui Xu
//
#pragma once
#include "WceUiCommon.h"
#include "wceui.h"

#define DBCLICK_DEFALUT_DELAY 300
#define DBCLICK_DEFALUT_X_DIST 8
#define DBCLICK_DEFALUT_Y_DIST 8

//if you want to get double-click message, you must handle mouse-down and mouse-up message.
//the message sequence is:
//step1. lbuttondown
//step2. lbuttonup
//step3. lbuttondown(double-click)
//step4. lbuttonup.


//usage:
//CWceUiStatic is an example, which source code is open.

//support CXXXLayer want to hanle double-click message

//in CXXXLayer::CXXXLayer()
//{
//    Init...
//}

//in CXXXLayer::OnLButtonDown
//if (!m_HandleDbClick.IsDbClick(...))
//{
//	 only left button down...
//}
//please pay attention to IsDbClick, in the IsDbClick, it call m_pLayer->OnLButtonDblClk(nFlags, point);

//in CXXXLayer::OnLButtonUp
// call RecordLButtonUp(...)

class CWceUiLayer;
class CWceUiDbClick
{
public:
	CWceUiDbClick(void);
	~CWceUiDbClick(void);

	//pLayer: which layer want to hanle double-click message
	void Init(CWceUiLayer* pLayer, DWORD dwDelay = DBCLICK_DEFALUT_DELAY, 
		int xDist = DBCLICK_DEFALUT_X_DIST, int yDist = DBCLICK_DEFALUT_Y_DIST);
	void UnInit();

	//record and check the left button down message
	BOOL IsDbClick(UINT nFlags, POINT point);
	//record the left button up message
	void RecordLButtonUp(UINT nFlags, POINT point);

private:
	typedef enum eMOUSE_ACTION_STATUS
	{
		E_LBUTTON_BEGIN,
		E_LBUTTON_DOWN,
		E_LBUTTON_DOWN_UP,
	}MOUSE_ACTION_STATUS;

	CWceUiLayer* m_pLayer;
	int			 m_xDist;
	int			 m_yDist;
	DWORD		 m_dwLastDownTickCount;
	DWORD		 m_dwDelay;
	POINT		 m_ptDownLast;

	MOUSE_ACTION_STATUS m_MouseStatus;

private:
	CWceUiDbClick (const CWceUiDbClick &);
	CWceUiDbClick & operator=(const CWceUiDbClick &);

};


